from flask import Blueprint, request, render_template, flash, redirect, url_for

from utils import response
from services.swiper_service import SwiperService

# 创建蓝图
admin_swiper_bp = Blueprint('admin_swiper', __name__)



@admin_swiper_bp.route('/list', methods=['GET'])
def list():
    data = SwiperService.list()

    return render_template('swiper/list.html', data=data)


@admin_swiper_bp.route('/add', methods=['POST'])
def add():
    if 'file' not in request.files:
        return response(400, '没有选择文件上传')

    file = request.files['file']
    name = request.form.get('name')

    SwiperService.add(name, file)

    return response(200, '文件上传成功')


@admin_swiper_bp.route('/delete/<id>', methods=['DELETE'])
def delete(id):
    SwiperService.delete_by_id(id)
    return response(200, '删除成功')
